<?php
/**
 * CONTENIDO extension pack (mpContenidoX), consists of multiple classes to
 * provide more features for Plugins/Modules.
 *
 * @package     mpContenidoX
 * @subpackage  VariableStorage
 * @author      Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2008-2012 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: Factory.class.php 21 2012-07-16 21:33:14Z purcaholic $
 * @todo        Error handling
 */


defined('CON_FRAMEWORK') or die('Illegal call');


/**
 * Factory class to get an instance of one of variable storage container classes
 *
 * <code>
 * // mpVariableStorage_ContainerFile example
 * $options['key'] = '/full/path/to/config.php';
 * $config = mpVariableStorage_Factory::get('filestorage', $options);
 *
 * // mpVariableStorage_ContainerDB example
 * $options['key'] = '/full/path/to/config.php';
 * $config = mpVariableStorage_Factory::get('dbstorage', $options);
 * </code>
 *
 * @package     mpContenidoX
 * @subpackage  VariableStorage
 * @author      Murat Purc <murat@purc.de>
 */
class mpVariableStorage_Factory
{

    /**
     * Returns a instance of desired variable storage container class
     *
     * @param   string  $name  Type of variable storage container ('filestorage' or 'dbstorage')
     *                         Note: 'serializer' is deprecated, use 'filestorage' instead
     * @param   array   $options  Options array
     * @return  mpVariableStorage_Interface  A object based on a mpVariableStorage_Interface implementation
     */
    public static function get($name, $options)
    {
        if ($name == 'filestorage') {
            return new mpVariableStorage_ContainerFile($options);
        } elseif ($name == 'dbstorage') {
            return new mpVariableStorage_ContainerDB($options);
        }
        return new mpVariableStorage_ContainerFile($options);
    }

}
